package com.huadao.pda.common;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GsonUtil {
    private static final GsonUtil ourInstance = new GsonUtil();
    private Gson gson;

    public static GsonUtil getInstance() {
        return ourInstance;
    }

    private GsonUtil() {
        if(gson==null){
            gson=new GsonBuilder()
                    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
        }
    }

    public Gson getGson() {
        return gson;
    }

    public <T> T fromJson(String jsonStr,Class<T> classOfT){
        try {
            return gson.fromJson(jsonStr,classOfT);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
